﻿using DevComponents.DotNetBar;
using ESRI.ArcGIS.Display;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlanningGIS.ArcGIS;

namespace PlanningGIS.Symbol
{
    /// <summary>
    /// 矢量符号
    /// </summary>
    public partial class FrmVectorStyle : OfficeForm
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public FrmVectorStyle()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 加载窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmVectorStyle_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        private ISymbol _SelectedSymbol = null;

        /// <summary>
        /// 获取或设置选择的符号
        /// </summary>
        public ISymbol SelectedSymbol
        {
            get { return _SelectedSymbol; }
            set
            {
                _SelectedSymbol = value;
                if (_SelectedSymbol is IMarkerSymbol)
                {
                    sptbStyle.SelectedTab = tbitmPoint;
                    markerStyle1.SelectedSymbol = _SelectedSymbol;
                    markerStyle1.InitControl();
                }
                else if (_SelectedSymbol is ILineSymbol)
                {
                    sptbStyle.SelectedTab = tbitmLine;
                    lineStyle1.SelectedSymbol = _SelectedSymbol;
                    lineStyle1.InitControl();
                }
                else if (_SelectedSymbol is IFillSymbol)
                {
                    sptbStyle.SelectedTab = tbitmPoly;
                    polyStyle1.SelectedSymbol = _SelectedSymbol;
                    polyStyle1.InitControl();
                }
                else if (_SelectedSymbol is ITextSymbol)
                {
                    sptbStyle.SelectedTab = tbitmAnno;
                    textStyle1.SelectedSymbol = _SelectedSymbol;
                    textStyle1.InitControl();
                }
            }
                
        }
        
        /// <summary>
        /// 
        /// </summary>
        public event SymbolChanged SelectChanged = null;

        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (sptbStyle.SelectedTab == tbitmPoint) _SelectedSymbol = markerStyle1.SelectedSymbol;
            else if (sptbStyle.SelectedTab == tbitmLine) _SelectedSymbol = lineStyle1.SelectedSymbol;
            else if (sptbStyle.SelectedTab == tbitmPoly) _SelectedSymbol = polyStyle1.SelectedSymbol;
            else if (sptbStyle.SelectedTab == tbitmAnno) _SelectedSymbol = textStyle1.SelectedSymbol;
            SelectChanged?.Invoke(this, new SymbolEventArgs() { NewSymbol = SelectedSymbol });
            Close();
        }

        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmVectorStyle_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Visible = false;
            
        }

        /// <summary>
        /// 符号化窗体
        /// </summary>
        static FrmVectorStyle _FrmStyle = null;

        /// <summary>
        /// 显示符号化窗体
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static void ShowStyle(ISymbol symbol, IWin32Window owner, SymbolChanged callback)
        {
            _FrmStyle = new FrmVectorStyle();
            _FrmStyle.SelectedSymbol = symbol;
            _FrmStyle.SelectChanged += callback;
            _FrmStyle.ShowDialog(owner);
            //if (_FrmStyle.Visible == false) _FrmStyle.Show(owner);
            //else _FrmStyle.BringToFront();
        }
        
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void SymbolChanged(object sender, SymbolEventArgs e);

    /// <summary>
    /// 
    /// </summary>
    public class SymbolEventArgs : EventArgs
    {
        /// <summary>
        /// 
        /// </summary>
        public ISymbol NewSymbol { get; set; }
    }

}
